<html>
<head><meta charset="utf-8"><title>who expects a type? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html">who expects a type?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197313129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197313129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197313129">(May 12 2020 at 17:50)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> for the "expected type foo found bar" style messages, who is "expecting"? Can we change that to explicitly say what expects it?</p>



<a name="197313369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197313369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197313369">(May 12 2020 at 17:52)</a>:</h4>
<p>Updating</p>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
 --&gt; src/main.rs:4:10
  |
4 |     demo(&quot;hi&quot;);
  |          ^^^^ expected `i32`, found `&amp;str`
</code></pre></div>


<p>to</p>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
 --&gt; src/main.rs:4:10
  |
4 |     demo(&quot;hi&quot;);
  |          ^^^^ the function `demo` expected `i32`, found `&amp;str`
</code></pre></div>


<p>maybe even </p>
<blockquote>
<p><code> expected this argument to be a `i32`, but it is `&amp;str` </code></p>
</blockquote>



<a name="197316350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197316350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197316350">(May 12 2020 at 18:14)</a>:</h4>
<p>I guess this does occur sometimes:</p>
<div class="codehilite"><pre><span></span><code>--- expected `f64` because of return type
</code></pre></div>



<a name="197317030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197317030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197317030">(May 12 2020 at 18:20)</a>:</h4>
<p>some cases do highlight the site of expectation like</p>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
 --&gt; src/main.rs:5:18
  |
5 |     let b: i32 = &quot;123&quot;;
  |            ---   ^^^^^ expected `i32`, found `&amp;str`
  |            |
  |            expected due to this
</code></pre></div>



<a name="197317185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197317185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197317185">(May 12 2020 at 18:21)</a>:</h4>
<p>though most of the time i do find E0308 confusing because it is not very clear whether the marked expression is the "expected" or the "found"</p>



<a name="197317271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197317271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197317271">(May 12 2020 at 18:22)</a>:</h4>
<p>My gut tells me that if we say what / why it's expected (more frequently, perhaps), then it would be more quickly digested. I'm pretty sure I've trained my brain to just ignore the "expected" / "found" text.</p>



<a name="197322464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197322464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197322464">(May 12 2020 at 19:01)</a>:</h4>
<p>The pointed element should always be the found one</p>



<a name="197322509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197322509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197322509">(May 12 2020 at 19:01)</a>:</h4>
<p>The problem we have is that these cases usually come from obligations</p>



<a name="197322601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197322601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197322601">(May 12 2020 at 19:02)</a>:</h4>
<p>I've been working in this but the cases that are left are becoming harder and harder</p>



<a name="197322668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197322668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197322668">(May 12 2020 at 19:02)</a>:</h4>
<p>And sadly I'm many cases all I can do is reconstruct what went wrong because we drop a lot of info during typeck</p>



<a name="197322699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197322699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197322699">(May 12 2020 at 19:02)</a>:</h4>
<p>Keeping that info around would balloon mem usage, which is a no-no</p>



<a name="197326339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197326339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197326339">(May 12 2020 at 19:28)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> I wonder if we've explored e.g. re-running typeck in "collection" mode if it detects an error at first to gather better explanations</p>



<a name="197326391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197326391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197326391">(May 12 2020 at 19:29)</a>:</h4>
<p>I'd guess it'd be pretty hard to make that work well? But I don't think I've seen PRs in that direction at all</p>



<a name="197327412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/who%20expects%20a%20type%3F/near/197327412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/who.20expects.20a.20type.3F.html#197327412">(May 12 2020 at 19:37)</a>:</h4>
<p>I've looked into it, but I doubt well ever get good at global analysis as things stand. Anything inside a given FnCtxt has potential</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>